import os
from dotenv import load_dotenv

# 加载环境变量（优先从.env文件加载，然后是系统环境变量）
load_dotenv()


class Settings:
    # 项目信息
    PROJECT_NAME = "鹰迅AI聊天系统"
    PROJECT_VERSION = "1.0.0"

    # 数据库配置
    MYSQL_USER = os.getenv("MYSQL_USER", "root")
    MYSQL_PASSWORD = os.getenv("MYSQL_PASSWORD", "123123")
    MYSQL_HOST = os.getenv("MYSQL_HOST", "localhost")
    MYSQL_PORT = os.getenv("MYSQL_PORT", "3306")
    MYSQL_DATABASE = os.getenv("MYSQL_DATABASE", "ai_chat")

    # 数据库连接URL
    SQLALCHEMY_DATABASE_URL = f"mysql+pymysql://{MYSQL_USER}:{MYSQL_PASSWORD}@{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_DATABASE}?charset=utf8mb4"

    # Redis配置
    REDIS_HOST = os.getenv("REDIS_HOST", "localhost")
    REDIS_PORT = os.getenv("REDIS_PORT", "6379")
    REDIS_DB = os.getenv("REDIS_DB", 0)
    REDIS_PASSWORD = os.getenv("REDIS_PASSWORD", "")

    # JWT配置
    SECRET_KEY = os.getenv("SECRET_KEY", "your-secret-key")
    ALGORITHM = "HS256"
    ACCESS_TOKEN_EXPIRE_MINUTES = 7200  # token有效期（分钟）

    # 豆包AI配置 - 从环境变量加载，提供默认值
    DOUBAO_API_KEY = os.getenv("DOUBAO_API_KEY", "API_KEY")
    DOUBAO_MODEL = os.getenv("DOUBAO_MODEL", "MODEL_ID")
    DOUBAO_API_BASE_URL = os.getenv("DOUBAO_API_BASE_URL", "https://ark.cn-beijing.volces.com/api/v3")


# 创建全局配置实例
settings = Settings()
